package com.xrz.controller;

import com.xrz.common.Result;
import com.xrz.pojo.UserInfo;
import com.xrz.service.UserInfoService;
import com.xrz.utils.FileUpload;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;

@Api(tags="用户信息")
@RestController
@RequestMapping("userInfo")
public class UserInfoController {

    final
    UserInfoService userInfoService;

    public UserInfoController(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }

    //根据uid获取用户信息
    @ApiOperation(value="根据uid获取用户信息")
    @GetMapping("getUserInfo/{uid}")
    public Result<?> getUserInfo(@PathVariable String uid){
        return userInfoService.getUserInfo(uid);
    }

    //修改用户信息
    @ApiOperation(value="修改用户信息,uid必传")
    @PostMapping(value ="updateUserInfo/",produces = "application/json;charset=utf-8")
    public Result<?> updateUserInfo(@RequestParam(value = "headImg") MultipartFile file, UserInfo userInfo) throws IOException {

        userInfo.setHead(FileUpload.saveFile(file));
        return userInfoService.updateUserInfo(userInfo);
    }
}
